/*
 * Copyright 2013-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.springframework.cloud.gateway.handler.predicate;

import org.springframework.cloud.gateway.support.ArgumentHints;
import org.springframework.cloud.gateway.support.NameUtils;
import org.springframework.tuple.Tuple;
import org.springframework.web.server.ServerWebExchange;

import java.util.function.Predicate;

/**
 * @author Spencer Gibb
 */
@FunctionalInterface
public interface RoutePredicateFactory extends ArgumentHints {

    String PATTERN_KEY = "pattern";

	/**核心方法，即函数接口的唯一抽象方法，用于生产Predicate
	 * @param args
	 * @return
	 */
	Predicate<ServerWebExchange> apply(Tuple args);

	/**调用NameUtils#normalizePredicateName(Class)方法，获得RoutePredicateFactory的名字。该方法截取类名前半段，例如QueryRoutePredicateFactory的结果为Query
	 * @return
	 */
	default String name() {
		return NameUtils.normalizePredicateName(getClass());
	}

}
